package com.example.universita.esami;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;

import com.androidplot.Plot;
import com.androidplot.series.XYSeries;
import com.androidplot.xy.LineAndPointFormatter;
import com.androidplot.xy.SimpleXYSeries;
import com.androidplot.xy.XYPlot;
import com.androidplot.xy.XYStepMode;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Profilo {
	
	String defaultName = new String("Inserisci nome");
	String defaultSurname = new String("Inserisci cognome");
	final String defaultStudentId = new String("00000");
	final int numberOfStudyYears = 6; 
	static final String nameSharedFile = new String("Profilo");
	
	private String nome = new String(); 
	private String cognome = new String();
	private String matricola = new String(); 
	
	private int posFacolta; 
	private int posSpecial;
	private int posCorso;
	
	private boolean check[] = new boolean[numberOfStudyYears];
	private boolean check_special[] = new boolean[numberOfStudyYears];
	
	// COSTRUTTORE 
	Profilo(Context context){
		int i;
		
		nome = defaultName;
        cognome = defaultSurname;
        matricola = defaultStudentId;	
        
        posFacolta=posSpecial=posCorso=0;
        
		for(i=0; i<numberOfStudyYears; i++) check[i] = false;
		for(i=0; i<numberOfStudyYears; i++) check_special[i] = false;
		
	}
	
	// METODI GET
	public String getName() { return nome; }
	public String getSurname() { return cognome; }
	public String getStudentId() { return matricola; }
	public int getIdFaculty() { return posFacolta; }
	public int getIdCourse() { return posCorso; }
	public int getIdSpecial() { return posSpecial; }
	public boolean getYearCheck(int index) { 
		if(index>=0 && index<numberOfStudyYears)
			 return check[index];
		return false;
	}
	
	public boolean getYearCheckSpecial(int index) { 
		if(index>=0 && index<numberOfStudyYears)
			 return check_special[index];
		return false;
	}
	// METODI SET
	public void setName(String newName) { nome = newName; }
	public void setSurname(String newSurname) { cognome = newSurname; }
	public void setStudentId(String newStudentId) { matricola = newStudentId; }
	public void setIdFaculty(int newId) { posFacolta = newId; }
	public void setIdCourse(int newId) { posCorso = newId; }
	public void setIdSpecial(int newId) { posSpecial = newId; }
	public void setYearCheck(int index, boolean value) { 
		if(index>=0 && index<numberOfStudyYears)
			check[index] = value;
	}
	public void setYearCheckSpecial(int index, boolean value) { 
		if(index>=0 && index<numberOfStudyYears)
			check_special[index] = value;
	}
	
	// METODI DI CONTROLLO
	public boolean isValidDatePerson(){
		if(nome.isEmpty() || nome.compareTo(defaultName) == 0 || cognome.isEmpty() || cognome.compareTo(defaultSurname) == 0 || 
		   matricola.compareTo(defaultStudentId) == 0 || posFacolta == 0 || posCorso == 0 )
			   return false;
		return true;
	}
	
	public boolean isValidStudyYears(){
		int i;
		
		for(i=0; i<numberOfStudyYears; i++)
			if(check[i])
				return true;
		return false;
	}
	
	public boolean isValidStudyYearsSpecial(){
		int i;
		
		for(i=0; i<numberOfStudyYears; i++)
			if(check_special[i])
				return true;
		return false;
	}
	
	public boolean isValidName(){
		if(nome.isEmpty() || nome.compareTo(defaultName) == 0)
			return false;
		return true;
	}
	
	public boolean isValidSurname(){
		if(cognome.isEmpty() || cognome.compareTo(defaultSurname) == 0)
			return false;
		return true;
	}
	
	public boolean isValidStudentId(){
		if(matricola.compareTo(defaultStudentId) == 0 || matricola.length() < 5)
			return false;
		return true;
	}
	
	public boolean isValidIdFaculty(){
		if(posFacolta == 0)
			return false;
		return true;
	}
	
	public boolean isValidIdCourse(){
		if(posCorso == 0)
			return false;
		return true;
	}
	
	public boolean isValidIdSpecial(){
		if(posSpecial == 0)
			return false;
		return true;
	}
	
	// GESTIONE DELLA SHARED PREFERENCES DEL PROFILO
	public void saveOnShared(SharedPreferences onSave, String nameFaculty, String nameCourse, String nameSpecial){
		SharedPreferences.Editor editor = onSave.edit();
		
		editor.putString("Nome", nome);
		editor.putBoolean("FlagProcedura", true);
		editor.putString("Cognome", cognome);
		editor.putString("Matricola", matricola);
		editor.putString("Facolta", nameFaculty);
		editor.putString("Corso", nameCourse);
		editor.putString("Special", nameSpecial);
		   
		editor.commit();
	}
	
	public String getNameOnShared(SharedPreferences onSave){
		return onSave.getString("Nome", "Nessun Valore Inserito");
	}
	
	public String getSurnameOnShared(SharedPreferences onSave){
		return onSave.getString("Cognome", "Nessun Valore Inserito");
	}
	
	public String getStudentIdOnShared(SharedPreferences onSave){
		return onSave.getString("Matricola", "Nessun Valore Inserito");
	}
	
	public String getFacultyOnShared(SharedPreferences onSave){
		return onSave.getString("Facolta", "Nessun Valore Inserito");
	}
	
	public String getCourseOnShared(SharedPreferences onSave){
		return onSave.getString("Corso", "Nessun Valore Inserito");
	}
	
	public String getSpecialOnShared(SharedPreferences onSave){
		return onSave.getString("Special", "Nessun Valore Inserito");
	}
	
	public boolean getProcedure(SharedPreferences onSave){
		return onSave.getBoolean("FlagProcedura", false);
	}
	
	public String getNameSharedFile(){
		return nameSharedFile;
	}
}